package org.example.redirect.console.controller;

import org.example.redirect.console.common.Util;
import org.springframework.boot.SpringApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(path={""})
public class RedirectController {
    @GetMapping(path={"exit"})
    public void exit(){
        if(Util.context==null) {
            System.out.println("System.exit");
            System.exit(0);
        }
        else {
            System.out.println("SpringApplication.exit");
            SpringApplication.exit(Util.context);
        }
    }

    @GetMapping(path={"err"})
    public String err(@RequestParam(value="i", required = false)Integer i){
        try {
            System.out.println(String.format("i/10=%s, dayStr=%s, dirStr=%s", i/10, Util.dayStr, Util.dirStr));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "err";
    }
}
